// com.ruoyi.platform.service.impl.PlatformDashboardServiceImpl.java
package com.ruoyi.platform.service.impl;

import com.ruoyi.platform.domain.vo.DashboardStatsVO;
import com.ruoyi.platform.mapper.PlatformDashboardMapper;
import com.ruoyi.platform.service.IPlatformDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * 平台数据大屏Service业务层处理
 */
@Service
public class PlatformDashboardServiceImpl implements IPlatformDashboardService {

    @Autowired
    private PlatformDashboardMapper platformDashboardMapper;

    @Override
    public DashboardStatsVO getDashboardStats() {
        // 获取基础统计数据
        DashboardStatsVO stats = new DashboardStatsVO();
        stats.setTodayOrderCount(platformDashboardMapper.selectTodayOrderCount());
        stats.setTodayPlatformRevenue(platformDashboardMapper.selectTodayPlatformRevenue());
        stats.setTodayNewUserCount(platformDashboardMapper.selectTodayNewUserCount());
        stats.setTodayAvgOrderValue(platformDashboardMapper.selectTodayAvgOrderValue());
        
        // 获取当前年月
        String currentYearMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
        
        // 获取本月订单统计
        List<DashboardStatsVO.DailyOrderStats> monthlyOrderStats = 
            platformDashboardMapper.selectMonthlyOrderStats(currentYearMonth);
        stats.setMonthlyOrderStats(monthlyOrderStats);
        
        // 获取本月营业额统计
        List<DashboardStatsVO.DailyRevenueStats> monthlyRevenueStats = 
            platformDashboardMapper.selectMonthlyRevenueStats(currentYearMonth);
        stats.setMonthlyRevenueStats(monthlyRevenueStats);
        
        return stats;
    }
}